//
// Created by tang on 23-3-25.
//

#ifndef PIINFO_IMAGE_HPP
#define PIINFO_IMAGE_HPP

#include <sdk_config.h>
#include <resource/resource.hpp>

class PI_API ImageContent final {
public:
    ImageContent(const u8* dat, u32 size);
    ImageContent(const std::string &path);
    ~ImageContent();

    ImageContent(const ImageContent&) = delete;
    ImageContent &operator=(const ImageContent&) = delete;

    inline void *handle() const { return img; }
private:
    void *img;
};

// PI_INLINE ImageContent *create_image_from_resource(const std::string &res_path) {
//     auto const content = MY_RESOURCE->get_file_content (res_path);
//     return new ImageContent {content.data(), (u32)content.size()};
// }

#define RESOURCE_IMAGE(out_var, res_path) \
do { \
    out_var = nullptr; \
    auto const content = MY_RESOURCE->get_file_content (res_path); \
    if (!content.empty ()) { \
        out_var = new ImageContent {content.data(), (u32)content.size()}; \
    } \
} while (0)

#endif  // PIINFO_IMAGE_HPP
